﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using SpiritEngine;
using SpiritEngine.Components2D;


namespace SimNations.City
{
    public class CityTileSprite : SpiritEngine.Components2D.C2D_Sprite
    {
        // MEMBER VARIABLES
        // ------------------------------------------------------------------------------------------------------------------------

        private CityTile m_ParentCityTile = null;


        // CONSTRUCTORS
        // ------------------------------------------------------------------------------------------------------------------------

        public CityTileSprite()
        {
        } // end CityTileSprite::CityTileSprite()

        public CityTileSprite(float x, float y, float rotation, string strFilename)
            : base(x, y, rotation, strFilename)
        {

        } // end CityTileSprite::CityTileSprite(float, float, float, string)


        // PRIVATE/PROTECTED METHODS
        // ------------------------------------------------------------------------------------------------------------------------

        protected override void Load()
        {
            if (m_t2dSpriteTexture == null)
            {
                m_t2dSpriteTexture = new Texture2D(ParentCityTile.ParentCity.ParentGameScreen.Engine.GraphicsDevice, m_rectSource.Width, m_rectSource.Height);
            }

            m_t2dSpriteTexture = ParentCityTile.ParentCity.ParentGameScreen.Engine.Content.Load<Texture2D>(m_strFilename);

            // Don't set the SourceRectangle property now if it has already been set
            if (m_rectSource == new Rectangle())
                m_rectSource = new Rectangle(0, 0, m_t2dSpriteTexture.Width, m_t2dSpriteTexture.Height);

            m_v2Origin = new Vector2(m_rectSource.Width / 2f,
                                     m_rectSource.Height / 2f);

        } // end void CityTileSprite::Load()

        protected override void ResetRenderStates()
        {
            ParentCityTile.ParentCity.ParentGameScreen.Engine.GraphicsDevice.RenderState.DepthBufferEnable = true;
            ParentCityTile.ParentCity.ParentGameScreen.Engine.GraphicsDevice.RenderState.AlphaBlendEnable = false;
            ParentCityTile.ParentCity.ParentGameScreen.Engine.GraphicsDevice.RenderState.AlphaTestEnable = false;

        } // end C2D_Sprite::ResetRenderStates()


        // DEBUG METHODS
        // ------------------------------------------------------------------------------------------------------------------------

#if (DEBUG)
        // put all debug methods in here...
#endif


        // METHODS
        // ------------------------------------------------------------------------------------------------------------------------

        public override void Draw()
        {
            DrawOffset(ParentCityTile.ParentCity.Position);

        } // end CityTileSprite::Draw()


        // PROPERTIES
        // ------------------------------------------------------------------------------------------------------------------------

        public CityTile ParentCityTile
        {
            get
            {
                return m_ParentCityTile;
            }
            set
            {
                if (value != null)
                    m_ParentCityTile = value;
            }
        }


        // EVENTS
        // ------------------------------------------------------------------------------------------------------------------------






    } // end class CityTileSprite

}
